/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.bo;

import org.ipti.br.tag.dao.NeighborhoodFacade;
import org.ipti.br.tag.entity.City;
import org.ipti.br.tag.entity.Neighborhood;
import org.ipti.br.tag.entity.Zipcode;
import java.util.Calendar;
import java.util.List;
import javax.inject.Inject;
import javax.ejb.Stateless;

/**
 *
 * @author israel
 */
@Stateless
public class NeighborhoodBO {

    @Inject
    private NeighborhoodFacade neighborhoodDAO;

    public NeighborhoodFacade getNeighborhoodDAO() {
        return neighborhoodDAO;
    }
    
    public void create(Neighborhood neighborhood){
        getNeighborhoodDAO().create(neighborhood);
    }

    public Neighborhood createOrRefresh(String name, Zipcode zipcode) {
        Neighborhood neighborhood = searchByNameCity(name,zipcode.getCity().getId());

        if (neighborhood == null) {
            neighborhood = new Neighborhood(name,zipcode.getCity());
            getNeighborhoodDAO().create(neighborhood);
        }
        return neighborhood;
    }

    public void edit(Neighborhood neighborhood) {
        getNeighborhoodDAO().edit(neighborhood);
    }

    public void remove(Neighborhood neighborhood) {
        getNeighborhoodDAO().remove(neighborhood);
    }

    public Neighborhood find(Object id) {
        return getNeighborhoodDAO().find(id);
    }

    public List<Neighborhood> findAll() {
        return getNeighborhoodDAO().findAll();
    }

    public List<Neighborhood> findAllOrder() {
        return getNeighborhoodDAO().findAllOrder();
    }
    
    public Neighborhood searchByNameCity(String name, Long cityID) {
        return getNeighborhoodDAO().searchByNameCity(name, cityID);
    }
    
    public List<String> neighborhoodList(String name, City city) {
        return getNeighborhoodDAO().neighborhoodList(name, city);
    }
    
    public List<Neighborhood> modifiedNeighborhoodBetweenDate(Calendar initialDate, Calendar finalDate, Long serialNumber) {
        return getNeighborhoodDAO().modifiedNeighborhoodBetweenDate(initialDate, finalDate, serialNumber);
    }
}
